43 Bar Charts - One Dimensional
43.1 Diagrammatic Presentation – One Dimensional – Bar Charts – Simple, Sub-divided and Multiple
43.2 Bar Charts
Bar charts are a staple of data visualization, used extensively to compare data across different categories. They are simple yet powerful tools for presenting categorical data with rectangular bars, where the length of each bar is proportional to the value it represents.
Bar charts can be classified into three types:
Simple Bar Chart: Displays data with simple bars placed at equal distances apart. Each bar represents a single value for a particular category.
Sub-divided (Stacked) Bar Chart: Shows multiple categories stacked on top of each other within a single bar. Each segment of the bar represents a sub-category of the overall category.
Multiple Bar Chart: Places bars next to each other rather than stacking, with each bar representing a different sub-category within the main category.
43.2.1 Simple Bar Chart
Structure:
A simple bar chart displays rectangular bars with lengths proportional to the values they represent. The bars are plotted either vertically or horizontally. A vertical bar chart is sometimes called a column chart. Each bar represents a single category, and the height or length of the bar corresponds to the data value.
Purpose:
Comparison: Simple bar charts are primarily used to compare the magnitude of values across different categories, making it easy to see which categories are larger or smaller. Clarity: They provide a clear, straightforward visualization of data, where the focus is on comparing single data points between individual categories.
R Code:
Python Code:
Code
import matplotlib.pyplot as plt
# Data
= ["Apple", "Banana", "Cherry"]
categories = [50, 30, 70]
values
# Simple Bar Chart
='blue')
plt.bar(categories, values, color"Simple Bar Chart")
plt.title("Fruit")
plt.xlabel("Quantity")
plt.ylabel( plt.show()
43.2.2 Sub-divided (Stacked) Bar Chart
Structure:
A stacked bar chart also displays rectangular bars, but each bar is divided into sub-sections that stack on top of each other vertically. Each sub-section represents a different sub-category within the main category.
Purpose:
Part-to-Whole Relationships: Stacked bar charts are used to show how different parts contribute to a whole across different categories. Comparison: While they allow comparison of the total sizes across categories, they are especially useful for comparing the segments within those totals.
R Code:
Code
# Data
categories <- c("Breakfast", "Lunch", "Dinner")
values1 <- c(20, 25, 30) # Eggs
values2 <- c(10, 15, 20) # Bacon
# Stacked Bar Chart
barplot(rbind(values1, values2), beside=FALSE, col=c("yellow", "red"),
legend.text=c("Eggs", "Bacon"), names.arg=categories,
main="Stacked Bar Chart", ylab="Quantity")
Python Code:
Code
import matplotlib.pyplot as plt
# Data
= ["Breakfast", "Lunch", "Dinner"]
categories = [20, 25, 30] # Eggs
values1 = [10, 15, 20] # Bacon
values2
# Stacked Bar Chart
='yellow', label='Eggs')
plt.bar(categories, values1, color='red', bottom=values1, label='Bacon')
plt.bar(categories, values2, color"Stacked Bar Chart")
plt.title("Meal")
plt.xlabel("Quantity")
plt.ylabel(
plt.legend() plt.show()
43.2.3 Multiple Bar Chart
Structure:
Multiple bar charts, or grouped bar charts, feature separate bars for each sub-category, placed next to each other rather than stacked. These are plotted across the same categories for ease of comparison.
Purpose:
Comparative Analysis: They are ideal for comparing multiple sub-categories across the same main categories. Visibility: Grouped bar charts provide a clear view of differences within categories, making it easier to compare each sub-category side by side without the complication of stacking.
R Code:
Code
# Data
categories <- c("Breakfast", "Lunch", "Dinner")
values1 <- c(20, 25, 30) # Eggs
values2 <- c(10, 15, 20) # Bacon
# Multiple Bar Chart
barplot(rbind(values1, values2), beside=TRUE, col=c("green", "orange"),
legend.text=c("Eggs", "Bacon"), names.arg=categories,
main="Multiple Bar Chart", ylab="Quantity")
Python Code:
Code
import matplotlib.pyplot as plt
import numpy as np
# Data
= ["Breakfast", "Lunch", "Dinner"]
categories = [20, 25, 30] # Eggs
values1 = [10, 15, 20] # Bacon
values2 = np.arange(len(categories)) # the label locations
x
# Multiple Bar Chart
= 0.35 # the width of the bars
width - width/2, values1, width, label='Eggs', color='green')
plt.bar(x + width/2, values2, width, label='Bacon', color='orange')
plt.bar(x
"Multiple Bar Chart")
plt.title("Meal")
plt.xlabel("Quantity")
plt.ylabel( plt.xticks(x, categories)
([<matplotlib.axis.XTick object at 0x10960ba10>, <matplotlib.axis.XTick object at 0x11e296030>, <matplotlib.axis.XTick object at 0x11e13f200>], [Text(0, 0, 'Breakfast'), Text(1, 0, 'Lunch'), Text(2, 0, 'Dinner')])
Code
plt.legend() plt.show()
Each type of bar chart serves different purposes and provides a clear visual differentiation of data. Depending on your specific needs—whether comparing total quantities, proportions within categories, or relationships between sub-categories—each format offers a tailored approach.